package com.ccsu.joysport.test;

import org.junit.Test;

import java.math.BigDecimal;
import java.math.RoundingMode;

public class JbfWriteExam {

    @Test
    public void test(){
        System.out.println(calculate4(10, 10, 10));
    }


    public int calculate1(int appleNum, int cmNum){
        return appleNum * 8 + cmNum * 13;
    }

    public int calculate2(int appleNum, int cmNum, int mgNum){
        return appleNum * 8 + cmNum * 13 + mgNum * 20;
    }

    public BigDecimal calculate3(int appleNum, int cmNum, int mgNum, boolean promotion) {
        return new BigDecimal(appleNum).multiply(new BigDecimal(8))
                .add(new BigDecimal(cmNum).multiply(new BigDecimal(13).multiply(new BigDecimal(promotion ? "0.8" : "1"))))
                .add(new BigDecimal(mgNum).multiply(new BigDecimal(20)));
    }

    public BigDecimal calculate4(int appNum, int cmNum, int mgNum) {
        BigDecimal bigDecimal = calculate3(appNum, cmNum, mgNum, false);
        BigDecimal divide = bigDecimal.divide(new BigDecimal(100), RoundingMode.DOWN);
        return bigDecimal.subtract(divide.multiply(new BigDecimal(10)));
    }

}
